home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Square of a floating point number.
- Date: 16 Apr 1996 15:00:35 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4l15a3INNcfo@keats.ugrad.cs.ubc.ca>
- References: <Dpo0Mn.DEo@ireq.hydro.qc.ca> <3172ACE2.45F6@delphi.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <3172ACE2.45F6@delphi.com>, S. F. Lott <slott@delphi.com> wrote:
- >Ryszard Pater wrote:
- >>
- >> How could I optimize for a speed the function to compute the square
- >> of a floating point number? I defined a function as follows:
- >> inline float sqr(float a) {return a*a;}
- >> or macro version
- >> #define sqr(a) ((a)*(a)).
- >> If You have a better solution give me a feed back, please.
- >>
- >> Ryszard
- >> pater@ireq.ca
- >
- >
- >Note, most C compilers generate code to expand floats
- >to doubles for purposes of doing arithmetic.
-
- Floats and doubles are terminology of the C language, not the underlying
- implementation. Whether or not the underlying implementation supports the
- storage of two precisions may affect the decision about how to assign the
- machine's idioms to C's floats and doubles.
-
- Fact: floating point execution units often have an even greater internal
- precision that is externally invisible. It may be outside of the instruction
- set's capabilities to specify a lower precision, so it cannot be said that the
- compiler can really do anything for the purposes of doing arithmetic other than
- generate code that prepares the operands. The internal precision used by the
- hardware cannot necessarily be equated with float, double or even long double.
- --
- I'm not really a jerk, but I play one on Usenet.
-